'use strict'

const Util = require('../../Lib/Util')
const BaseTable = require('../../BaseClass/BaseTable')
const Database = use('Database')
const log = use('Logger')

class McPricingIndexTable extends BaseTable {
  async getResults() {
    try {
      let result = await Database.select('parent_code', 'code', 'desc', 'input_type')
        .from(this.tabelName)
        .where('status', 1)
        .orderBy('sequence', 'asc')

      return Util.end({
        msg: 'OK',
        data: result,
      })
    } catch (err) {
      return Util.error({
        msg: err.message,
        track: 'joipo090',
      })
    }
  }

  async getPrices(obj) {
    try {
      let result = await Database.from(this.tabelName)
        .sum('index_human as sm')
        .avg('index_difficulty as dif')
        .whereIn('code', obj.code)

      return Util.end({
        msg: 'OK',
        data: result,
      })
    } catch (err) {
      return Util.error({
        msg: err.message,
        track: 'beiyao2',
      })
    }
  }
}

module.exports = McPricingIndexTable
